<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Modules\Midautumn\Entities\Ticket;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasRoles;

    public $guard_name = 'sanctum';


//    protected $appends = [
//        'isSuperAdmin',
//    ];
//

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    //默认加载information

    protected $fillable = ['id', 'name', 'mobile', 'avatar', 'email', 'member', 'password', 'approve'];

    protected $hidden = [
        'password',
        'remember_token',
    ];


    protected $casts = [
        'email_verified_at' => 'datetime',
        'approve' => 'array'
    ];

    public function roles()
    {
        return $this->morphToMany(Role::class, 'model', 'model_has_roles');
    }


    public function getUsernameAttribute()
    {
        return $this->name;
    }


    /**
     * 超级管理员
     * @return void
     */
    public function getIsSuperAdminAttribute()
    {
        return $this->id === 1;
    }

}
